package org.takinframework.web.webservice.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.jws.WebMethod;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.takinframework.core.common.exception.BusinessException;
import org.takinframework.core.common.service.impl.BaseServiceImpl;
import org.takinframework.web.buss.entity.JwebDepot;
import org.takinframework.web.buss.entity.JwebDepotOut;
import org.takinframework.web.buss.mapper.JwebDepotMapper;
import org.takinframework.web.webservice.JwebDepotDetailService;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;


@Transactional
@Component(value="jwebDepotDetailServiceImpl")
@Produces(value={MediaType.APPLICATION_JSON})
public class JwebDepotDetailServiceImpl extends BaseServiceImpl implements JwebDepotDetailService {
	@Autowired
	private JwebDepotMapper<JwebDepot, String> depotMapper;

	@GET
	@Path("depot")
	public String selectAll() throws BusinessException {
		JSONObject jsonObject = new JSONObject();
		List<JwebDepot> d = Lists.newArrayList();
		List<JwebDepotOut> dep = Lists.newArrayList();
		Map<String, JwebDepot> map = Maps.newHashMap();
		for (int i = 0; i < 5; i++) {
			JwebDepot de = new JwebDepot();
			de.setId("11111"+i);
			de.setNumber("number01"+i);
			JwebDepotOut o = new JwebDepotOut();
			o.setAveraTempera(20.1);
			o.setAveraHumidity(21.0);
			dep.add(o);
			de.setDepotOut(dep);
			d.add(de);
			map.put(de.getNumber(), de);
		}
		jsonObject.putAll(map);
		return jsonObject.toString();
	}

	
//	@WebMethod(operationName="selectAll")
//	public String selectAll() throws BusinessException {
////		List<JwebDepot> depots = depotMapper.selectAll();
//		JSONObject jsonObject = new JSONObject();
//		List<JwebDepot> d = Lists.newArrayList();
//		List<JwebDepotOut> dep = Lists.newArrayList();
//		Map<String, JwebDepot> map = Maps.newHashMap();
//		JwebDepot de = new JwebDepot();
//		de.setId("11111");
//		de.setNumber("number01");
//		for (int i = 0; i < 5; i++) {
//			JwebDepotOut o = new JwebDepotOut();
//			o.setAveraTempera(20.1);
//			o.setAveraHumidity(21.0);
//			dep.add(o);
//			de.setDepotOut(dep);
//		}
//		map.put(de.getNumber(), de);
//		jsonObject.putAll(map);
//		
//		return jsonObject.toString();
//	}

}
